*! 1.3 VERSION OF TRAVELTIME
program traveltime
	version 8.2 
	syntax, start_x(string) start_y(string) end_x(string) end_y(string) my_ak(string)

	quietly {

		local cnt = _N   
		g traveltime = .
		g traveltime_dist = .
		tempfile txtfile 
  
		forval i = 1/`cnt' {
			local sx = `start_x'[`i']
			local sy = `start_y'[`i']
			local ex = `end_x'[`i'] 
			local ey = `end_y'[`i']
			local ak = `my_ak'

			preserve

				copy "http://api.map.baidu.com/direction/v2/driving?origin=`sy',`sx'&destination=`ey',`ex'&ak=`ak'" "`txtfile'",replace
			   *noi: di 	"http://maps.google.com/maps?f=d&output=dragdir&saddr=`sy',`sx'&daddr=`ey',`ex'&dirflg=`dr'" "`txtfile'"	  		  
				insheet using "`txtfile'", clear nonames

				keep v11 v12

				split v11, p(":")
				split v12, p(":")

				keep v112 v122

				global dist = v112[1]
				global traveltime = v122[1]

			restore

			replace traveltime = $traveltime in `i'
			replace traveltime_dist = $dist in `i'
			
		}

	}


end

